Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make anyio.run_process() accept stdin argument #859

Merged
merged 9 commits into from
Jan 30, 2025

Conversation

jmehnle
Copy link
Contributor

@jmehnle jmehnle commented Jan 11, 2025

Changes

Make anyio.run_process() accept a stdin argument.

This is consistent with what asyncio.create_subprocess_exec(), trio.run_process(), and subprocess.run(), which accept such an argument.

The handling of conflicts between stdin and input arguments is simplistic: the latter currently overrides the former without warning.

Checklist

  • You've added tests (in tests/) added which would fail without your patch
  • You've updated the documentation (in docs/, in case of behavior changes or new
    features)
  • You've added a new changelog entry (in docs/versionhistory.rst).

This is consistent with what `asyncio.create_subprocess_exec()`, `trio.run_process()`, and `subprocess.run()`, which accept such an argument.

The handling of conflicts between `stdin` and `input` arguments is simplistic: the latter overrides the former without warning.
This new unit test may be able to replace the previously existing `test_run_process_connect_to_file` test, as `run_process()` internally just delegates to `open_process()`, so both are proven working by the new test.
@jmehnle jmehnle force-pushed the run_process-accepts-stdin branch from 59c708d to 0452d94 Compare January 23, 2025 23:48
Copy link
Owner

@agronholm agronholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'll just ask around if anyone has any objections.

Copy link

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handling of conflicts between stdin and input arguments is simplistic: the latter currently overrides the former without warning.

this feels like an unnecessary footgun with ~zero upside, I think you should add an

if stdin is not None and input is not None:
    raise ValueError("only one of stdin and input is allowed"

src/anyio/_core/_subprocesses.py Outdated Show resolved Hide resolved
@agronholm
Copy link
Owner

The handling of conflicts between stdin and input arguments is simplistic: the latter currently overrides the former without warning.

this feels like an unnecessary footgun with ~zero upside, I think you should add an

if stdin is not None and input is not None:
    raise ValueError("only one of stdin and input is allowed"

How do the upstream APIs handle it when both are passed?

@agronholm
Copy link
Owner

The handling of conflicts between stdin and input arguments is simplistic: the latter currently overrides the former without warning.

this feels like an unnecessary footgun with ~zero upside, I think you should add an

if stdin is not None and input is not None:
    raise ValueError("only one of stdin and input is allowed"

How do the upstream APIs handle it when both are passed?

Oh, right, this is an AnyIO only thing that we have. Never mind.

Copy link

@jakkdl jakkdl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just a missing test case for coverage

Comment on lines +88 to +89
if stdin is not None and input is not None:
raise ValueError("only one of stdin and input is allowed")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably want a test case for this.
(maybe look over coverage config to enforce 100% patch coverage?)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path coverage minimum set to 100% on Coveralls. Test case added.

@agronholm agronholm merged commit 3d61a68 into agronholm:master Jan 30, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants